const express = require('express');
const session = require('express-session');
const path = require('path');
const app = express();

// 根路由重定向到登录页面
app.get('/', (req, res) => {
    res.redirect('/login');
});

// 中间件设置
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(session({
    secret: 'your_secret_key',
    resave: false,
    saveUninitialized: false
}));

// 设置模板引擎
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

// 路由
app.use('/', require('./routes/auth'));
app.use('/todos', require('./routes/todos'));

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`服务器运行在端口 ${PORT}`);
}); 